package cn.net.dpi.shp.task;

import cn.net.dpi.shp.util.TaskUtils;
import lombok.Builder;
import lombok.Data;

import java.time.LocalDateTime;

/**
 * @author liuke
 * @date 2023/7/17
 */
@Data
@Builder
public class TaskExecutionConfig {
    private String taskName;
    private String tenantCode;
    private String taskAppId;
    private String environmentConfig;
    private String envFile;
    private String taskParams;
    private String executePath;
    private String logPath;
    private String taskLogName;
    private String queue;
    private LocalDateTime startTime;
    private int timeout;
    private String objId;
    private String flinkJobId;

    public static TaskExecutionConfig getDefaultInstance(boolean isDebug) {
        String tenantCode = "admin";
        int userId = 1;
        String jobAlias = "shp-parse";
        int jobVersion = 1;
        LocalDateTime firstSubmitTime = LocalDateTime.now();
        String taskAppId = TaskUtils.buildTaskAppId(tenantCode, userId, jobAlias, jobVersion, firstSubmitTime);
        String taskLogPath = TaskUtils.getTaskLogPath(firstSubmitTime, taskAppId);
        String taskLogName = TaskUtils.buildTaskId(firstSubmitTime, taskAppId);
        Thread.currentThread().setName(taskLogName);
        String taskParams = System.getenv().get("taskParams");
        if (isDebug) {
            //本地测试传入参数
            taskParams = "";
        }

        return TaskExecutionConfig.builder()
                .tenantCode(tenantCode)
                .taskName(jobAlias)
                .taskAppId(taskAppId)
                .logPath(taskLogPath)
                .taskLogName(taskLogName)
                .startTime(firstSubmitTime)
                .taskParams(taskParams)
                .timeout(60)
                .build();
    }
}
